package info.qingshui.browser.hk;

import info.qingshui.browser.BrowserApplication;

import info.qingshui.browser.hk.setting.Setting;
import info.qingshui.browser.R;




import android.os.AsyncTask;
import android.util.Log;

/**
 * 启动时要执行的异步任务
 * 
 */
public class StartupAsyncTask extends AsyncTask<BrowserApplication, Integer, Integer> {

	protected void onProgressUpdate(Integer... progress) {
		// [... Update progress bar, Notification, or other UI element ...]
		Log.d(StartupAsyncTask.class.getSimpleName(), "onProgressUpdate " + progress);
	}

	protected void onPostExecute(Integer... result) {
		// [... Report results via UI update, Dialog, or notification ...]
		Log.d(StartupAsyncTask.class.getSimpleName(), "onPostExecute " + result);
	}


	protected Integer doInBackground(BrowserApplication... browserApplications) { 
		Log.i(StartupAsyncTask.class.getSimpleName(), "doInBackground " );
		BrowserApplication browserApplication =browserApplications[0];
        try { 
        	try {
        		Thread.sleep(1000*2);
        	}  catch (Exception e) { 
        		
        	}
        	
        	//load配置文件
        	Setting setting = browserApplication.getSetting();
        	setting.setStartTimeNow();// 最后一次启动为当前
        	setting.updateSetting();
        	
        	browserApplication.getTracker().trackEvent(
    	            "LoginLogout",  // Category
    	            "Login",  // Action
    	            "common", // Label
    	            1);       // Value
    		
        	
        	//更新配置文件
        	//setting.updateSetting();
        	//setting.loadSetting();
        	

        } catch (Throwable e) {  
        	Log.e(StartupAsyncTask.class.getSimpleName(), "doInBackground error" ,e);
            return -1;  
        }  
        
        
		return 0;
	}
}
